package service.serviceImpl;

import dao.DepartInfoDao;
import dao.StuDao;
import dao.daoImpl.DepartInfoDaoImpl;
import dao.daoImpl.StuDaoImpl;
import pojo.Student;
import service.StuService;

import java.sql.SQLException;

public class StuServiceImpl implements StuService {

    StuDao stuDao = new StuDaoImpl();
    DepartInfoDao departInfoDao = new DepartInfoDaoImpl();
    @Override
    public Student findStuById(String id,boolean isChangeStuStatus) throws SQLException {

        //return stuDao.findStuById(id);

        Student stu = stuDao.findStuById(id);

        if (isChangeStuStatus){
            changeStuStatus(stu,departInfoDao);
        }
        return stu;
    }

    @Override
    public void changeStuStatus(Student stu,DepartInfoDao departInfoDao)throws SQLException{

        departInfoDao = new DepartInfoDaoImpl();

        //根据学生的部门信息(DepartInfo的id)，调用DepartInfoDao查找具体的部门信息，再将学生的部门信息设置为查找到的值
        stu.setStu_col_info(departInfoDao.findDepartStatus(stu.getStu_col_info()).getStatus());
        stu.setStu_org_info(departInfoDao.findDepartStatus(stu.getStu_org_info()).getStatus());
        stu.setStu_off_info(departInfoDao.findDepartStatus(stu.getStu_off_info()).getStatus());
        stu.setStu_youth_info(departInfoDao.findDepartStatus(stu.getStu_youth_info()).getStatus());
        stu.setStu_lib_info(departInfoDao.findDepartStatus(stu.getStu_lib_info()).getStatus());
        stu.setStu_domi_info(departInfoDao.findDepartStatus(stu.getStu_domi_info()).getStatus());
        stu.setStu_manage_info(departInfoDao.findDepartStatus(stu.getStu_manage_info()).getStatus());
        stu.setStu_fina_info(departInfoDao.findDepartStatus(stu.getStu_fina_info()).getStatus());
    }
    @Override
    public void updateStu(Student stu) throws SQLException {
          stuDao.updateStu(stu);
    }
}
